What is an Ansible Playbook?
An Ansible Playbook is a YAML file that contains plays, or groups of tasks, which describe actions to be performed on managed nodes (hosts). Each play in a playbook is executed sequentially on specified hosts.
Sample Playbook
Here’s an example playbook that installs the tree package on all hosts:
---
- name: Install tree Package
hosts: all
become: true
tasks:
- name: Install tree
yum:
name: tree
state: present
Explanation of Each Part
---: Start of the YAML file.name: Title of the play for readability.hosts: Specifies which hosts to run tasks on (here, all hosts).become: true: Enables privilege escalation.tasks: List of actions to be performed.
Running the Playbook
To execute the playbook, use the following command:
ansible-playbook install_tree.yml

Comments
Post a Comment